package com.wanke.service.impl;

import com.wanke.util.DateTimeUtils;
import com.wanke.domain.po.Measurement;
import com.wanke.service.MeasurementService;
import com.wanke.util.InfluxDBUtil;

import java.util.List;
import java.time.LocalDateTime;

public class MeasurementServiceImpl implements MeasurementService {

    private InfluxDBUtil influxDBUtil;

    public MeasurementServiceImpl(InfluxDBUtil influxDBUtil) {
        this.influxDBUtil = influxDBUtil;
    }

    @Override
    public void insertTempMeasurement(List<Measurement> measurements) {
        influxDBUtil.putTempData(measurements);
    }

    @Override
    public void insertBackMeasurement(List<Measurement> measurements) {
        influxDBUtil.putBackData(measurements);
    }

    @Override
    public List<Measurement> findTempAll(LocalDateTime end, int size, int page) {
        return influxDBUtil.getTempRowData(DateTimeUtils.asDate(end),size,page);
    }

    @Override
    public Long findMeasurementTempAllSize(LocalDateTime end) {
        return influxDBUtil.getTempCount(DateTimeUtils.asDate(end));
    }

    @Override
    public boolean deleteTempMeausremnet(LocalDateTime end) {
        return influxDBUtil.deleteTempRow(DateTimeUtils.asDate(end));
    }

    @Override
    public Long findMeasurementBackAllSize(String start, String end) {
        return influxDBUtil.getMeasurementBackCount(DateTimeUtils.formatToDate(start), DateTimeUtils.formatToDate(end));
    }

    @Override
    public List<Measurement> findMeasurementBackAll(String start, String end, int limit, int skip) {
        return influxDBUtil.getBackRowData(DateTimeUtils.formatToDate(start),DateTimeUtils.formatToDate(end),limit,skip);
    }

    @Override
    public void delete(LocalDateTime end) {
         influxDBUtil.deleteTempRow(DateTimeUtils.asDate(end));
    }
}
